#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/msg.h>

struct msgbuf {
    long mtype;
    char mtext[1];
};

int main(int argc, char *argv[])
{
    int mqid;
    size_t len;
    long type;
    struct msgbuf *ptr;

    if (argc != 4)
    {
        printf("usage: %s <pathname><#byte><type>\n", argv[0]);;
        exit(0);
    }

    len = atoi(argv[2]);
    type = atol(argv[3]);

    if ((mqid = msgget(ftok(argv[1], 0), 0000)) == -1)
    {
        perror("msgget error");
        exit(0);
    }

    ptr = (struct msgbuf *)calloc(sizeof(long)+len, sizeof(char));
    ptr->mtype = type;
    msgsnd(mqid, ptr, len, 0);

    return 0;
}
